int islandPerimeter(vector<vector<int>> &grid)
{
    int sum = 0, near = 0;
    for (int i = 0; i < grid.size(); i++)
    {
        for (int j = 0; j < grid[i].size(); j++)
        {
            if (grid[i][j] == 1)
            {
                sum++;
                if (i != 0 && grid[i - 1][j] == 1)
                {
                    near++;
                }
                if (j != 0 && grid[i][j - 1] == 1)
                {
                    near++;
                }
            }
        }
    }
    return sum * 4 - near * 2;
}